package com.ruoyi.bim.controller;

import com.ruoyi.framework.shiro.token.LoginType;
import com.ruoyi.framework.shiro.token.UserToken;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.subject.Subject;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Objects;

@Controller
@RequestMapping("agentMode")
public class LoginByAgentController {
    @RequestMapping("checkLogin")
    public String checkAgentHeader(@RequestHeader HttpHeaders headers,@CookieValue(name="AMSESSION") String userName){
        Subject subject = SecurityUtils.getSubject();
        UserToken usernamePasswordToken = new UserToken(userName.trim(), LoginType.NOPASSWD);
        try {
            subject.login(usernamePasswordToken);
            return "OAuth2Index";
        } catch (AuthenticationException e) {
            return "error/unauth";
        }
    }
}
